<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2016/11/8
 * Time: 下午10:20
 */
class ActivityService extends Service {

    public static function indexHeader(){
        $header = array(
            'RecDate'       => array('text' => '日期'),
            'SID'           => array('text' => '服'),
            'ActivityType'  => array('text' => '活动类型'),
            'ActivityId'    => array('text' => '活动ID'),
            'ActivityName'  => array('text' => '活动名称'),
//            'Money'         => array('text' => '产生货币数', 'rule' => 'numeric'),
//            'Mage'          => array('text' => '产生勾玉数', 'rule' => 'numeric'),
//            'ItemNumber'    => array('text' => '产生道具个数', 'rule' => 'numeric'),
//            'GiftNumber'    => array('text' => '产生礼包个数', 'rule' => 'numeric'),
            'ActProcNum'    => array('text' => '参与活动人数', 'rule' => 'numeric'),
            'ActProcCnt'    => array('text' => '参与活动人次', 'rule' => 'numeric'),
//            'GetNumber'     => array('text' => '完成人数', 'rule' => 'numeric'),
//            'GetCnt'        => array('text' => '完成人次', 'rule' => 'numeric'),
//            'Percent'       => array('text' => '完成人数比', 'rule' => 'percent'),
            'ActCurNum'     => array('text' => '参与活动累计次数', 'rule' => 'numeric'),
            'ActTargetNum'  => array('text' => '参与活动目标次数', 'rule' => 'numeric'),
        );

        return $header;
    }

    public static function indexData($params){
        $data = ModActivity::indexData($params);

        if($params['time_start'] == $params['time_end']){
            $date = $params['time_start'];
        }else{
            $date = date('Y.m.d', strtotime($params['time_start'])).'~'.date('Y.m.d', strtotime($params['time_end']));
        }

        PubFunc::parseDict($data, array('ActivityType' => PubDict::dict('roma', 'activitytype')));

        foreach($data as &$v){
            $v['RecDate']   = $date;
            $v['SID']       = $params['server'];
            $v['Percent']   = empty($v['GetNumber']) ? "0.00" : number_format($v['ActProcNum'] / $v['GetNumber'] * 100, 2) . '%';
        }
        unset($v);

        return $data;
    }

    public static function finishedHeader(){
        $header = array(
            'RecDate'           => array('text' => '日期'),
            'SID'               => array('text' => '服'),
            'ActivityType'      => array('text' => '活动类型'),
            'ActivityId'        => array('text' => '活动ID'),
            'ActivityName'      => array('text' => '活动名称'),
            'ActTargetUsers'    => array('text' => '符合活动的目标人数', 'rule' => 'numeric'),
            'ActProcNum'        => array('text' => '参与活动人数', 'rule' => 'numeric'),
            'ActProcCnt'        => array('text' => '参与活动人次', 'rule' => 'numeric'),
            'ActCompNum'        => array('text' => '完成活动的人数', 'rule' => 'numeric'),
            'ActCurNum'         => array('text' => '参与活动累计次数', 'rule' => 'numeric'),
            'ActTargetNum'      => array('text' => '参与活动目标次数', 'rule' => 'numeric'),
            'ActProcRate'       => array('text' => '活动参与度', 'rule' => 'percent'),
            'ActCompRate'       => array('text' => '活动完成度', 'rule' => 'percent'),
        );

        return $header;
    }

    public static function finishedData($params){
        $data = ModActivity::finishedData($params);

        if($params['time_start'] == $params['time_end']){
            $date = $params['time_start'];
        }else{
            $date = date('Y.m.d', strtotime($params['time_start'])).'~'.date('Y.m.d', strtotime($params['time_end']));
        }

        PubFunc::parseDict($data, array('ActivityType' => PubDict::dict('roma', 'activitytype')));

        foreach($data as &$v){
            $v['RecDate']       = $date;
            $v['SID']           = $params['server'];

            $v['ActProcRate']   = empty($v['ActTargetUsers']) ? "0.00" : number_format($v['ActProcNum'] / $v['ActTargetUsers'] * 100, 2) . '%';
            $v['ActCompRate']   = empty($v['ActProcNum']) ? "0.00" : number_format($v['ActCompNum'] / $v['ActProcNum'] * 100, 2) . '%';
        }
        unset($v);

        return $data;
    }

    public static function itemHeader(){
        $header = array(
            'RecDate'       => array('text' => '日期'),
            'ItemId'        => array('text' => '道具'),
            'GetNumber'     => array('text' => '获得数量', 'rule' => 'numeric'),
        );

        return $header;
    }

    public static function giftHeader(){
        $header = array(
            'RecDate'       => array('text' => '日期'),
            'GiftId'        => array('text' => '礼包'),
            'GetNumber'     => array('text' => '获得数量', 'rule' => 'numeric'),
        );

        return $header;
    }

    public static function itemData($params){
        $data = ModActivity::itemData($params);

        if($params['time_start'] == $params['time_end']){
            $date = $params['time_start'];
        }else{
            $date = date('m.d', strtotime($params['time_start'])).'~'.date('m.d', strtotime($params['time_end']));
        }

        foreach($data as &$v){
            $v['RecDate']   = $date;
            $v['SID']       = $params['server'];
        }
        unset($v);

        return $data;
    }

    public static function giftData($params){
        $data = ModActivity::giftData($params);

        if($params['time_start'] == $params['time_end']){
            $date = $params['time_start'];
        }else{
            $date = date('m.d', strtotime($params['time_start'])).'~'.date('m.d', strtotime($params['time_end']));
        }

        foreach($data as &$v){
            $v['RecDate']   = $date;
            $v['SID']       = $params['server'];
        }
        unset($v);

        return $data;
    }

    public static function dictActivity($game){
        return PubDict::dict($game, 'activityaction');
    }

    public static function dictActivityType(){
        return array(
            '' => 'ALL',
        ) + PubDict::dict('roma', 'activitytype');
    }

}